package com.lin.oss.config;

import com.lin.oss.adapter.AliYunStorageAdapter;
import com.lin.oss.adapter.MinioStorageAdapter;
import com.lin.oss.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@RefreshScope
public class StorageConfig {
    /**
     * minioUrl
     */
    @Value("${storage.service.type}")
    private String storageType;


    @Bean
    @RefreshScope
    public StorageAdapter storageService() {
        if("minio".equals(storageType)){
            return new MinioStorageAdapter();
        } else if ("aliyun".equals(storageType)) {
            return new AliYunStorageAdapter();
        }else{
            throw new IllegalArgumentException("未找到对应的文件存储处理器");
        }
    }
}
